/****************************************************
 * @class CategoryModelTreePanel
 * @extends Ext.tree.TreePanel
 ***************************************************/
	CategoryModelTreePanel = Ext.extend(Ext.tree.TreePanel,{
		create_category_win: null,
		constructor:function(config){
			Ext.apply(this,config);
			
			var edit_category_win;
			
			CategoryModelTreePanel.superclass.constructor.call(this, {
				id: 'tp_category_model',
				useArrows: false,
				autoScroll: true,
				nocache: true,
				animate: false,
				border: false,
				enableDD: true,
				containerScroll: true,
				rootVisible: true,
				loader: new Ext.tree.TreeLoader({
					dataUrl: '/pdm/category/asyncCategoryTree.htm'
				}),
				root: new Ext.tree.AsyncTreeNode({
					text: "模板节点",
					draggable: false,
					id: '46'
				}),
				tbar:[{
					id: 'create_cate',
					iconCls: 'cls_add_category_model',
					text: "新建",
					handler: function(){
						var parent_id = document.getElementById("_selected_node_id").value;
						
						var tp_category_model = Ext.getCmp("tp_category_model");
						var childNodeSize = tp_category_model.getNodeById(parent_id).childNodes.length;
						
						var info = {};
						info.parentId = parent_id;
						info.nextOrder = childNodeSize+1;
						
						if(parent_id == ""){
							Ext.Msg.alert("Notice:","Plz select the parent node first!");
						} else {
							this.create_category_win = Ext.getCmp("createCategoryWin");
							if(typeof(this.create_category_win) != "object")
							{
								this.create_category_win = new CreateCategoryWin({_parentId: parent_id})
							}
							this.create_category_win.reset(info);
							this.create_category_win.show();
						}
					}
				},'-',{
					id: 'edit_cate',
					text: "编辑",
					iconCls: 'cls_edit_category',
					handler: function(){
						var node_id = document.getElementById("_selected_node_id").value;
						if(node_id==""){
							alert("Plz select the parent node first!");
						}else{
							jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
							try{
								var info = jsonrpc.jabsorbService.getEditCateInfo(node_id);
							}catch(e){
								alert(e);
							}
							var jsonInfo = eval("("+info+")");
						
							if(!edit_category_win)
							{
								edit_category_win = new EditCategoryWin({node_info: jsonInfo});
							}
							
							edit_category_win.reset();
							edit_category_win.setValue(jsonInfo);
							
							edit_category_win.show();
						}
					}
				},'-',{
					id: 'delete_cate',
					text: "删除",
					iconCls: 'cls_remove_category_model',
					handler: function(){
						var cur_node_id = document.getElementById("_selected_node_id").value;
						if(cur_node_id==""){
							alert("Plz select the parent node first!");
						}else{
							Ext.MessageBox.show({
								title: "温馨提示：",
								msg: "您确认要删除此文件模板？",
								buttons: Ext.MessageBox.YESNO,
								fn: function(btn){
									if(btn == 'yes')
									{
										Ext.Ajax.request({
											url: '/pdm/category/deleteCate.htm',
											method: 'post',
											params: {
												cate_id: cur_node_id
											},
											success: function(response,options){
												Ext.Msg.alert("信息:"," * 删除成功 * ");
												var tp_cate_model = Ext.getCmp("tp_category_model");
									
												var parent_node = tp_cate_model.getNodeById(cur_node_id).parentNode;
												
												tp_cate_model.loader.load(parent_node);
												parent_node.expand(true,true);
											},
											failure: function(response){
												Ext.Msg.alert("信息:"," * 系统出错，请联系IS管理员 *"); 
											}
										});
									}
									else return;
								}
							});
						}
					}
				}]
			});
			
			this.on('click',function(node){
				document.getElementById("_selected_node_id").value = node.id;
				document.getElementById("_selected_node_text").value = node.text;
		    });
		    
		    this.on('beforemovenode', function(tree, node, oldParent, newParent, index) {
		    	Ext.MessageBox.show({
					title: "温馨提示：",
					msg: "您确认要调整["+node.text+"]?",
					buttons: Ext.MessageBox.YESNO,
					fn: function(btn){
						if(btn == 'yes')
						{
							Ext.Ajax.request({
								method: 'post',
								url: '/pdm/category/moveNode.htm',
								params: {
									nodeid: node.id,
									newparentid: newParent.id,
									oldparentid: oldParent.id,
									dropindex: index+1
								},
								success: function(response,options){
									tree.loader.load(oldParent);
									oldParent.expand(true,true);
								},
								failure: function(response){
									return false;
								}
							});
						}
						else return false;
					}
				});
				
			});
		}
	});

/****************************************************
 * @class CategoryModelTreeGrid
 * @extends Ext.ux.tree.TreeGrid
 ***************************************************/
	CategoryModelTreeGrid = Ext.extend(Ext.ux.tree.TreeGrid,{
		setTemplateWin: null,
		setRoleWin: null,
		create_category_win: null,
		edit_category_win: null,
		win_copyModel: null,
		constructor:function(config){
			Ext.apply(this,config);
			
			CategoryModelTreeGrid.superclass.constructor.call(this, {
				id: 'categoryModel_tree_grid',
				loadMask: {msg:'Loading...'},
				width: 600,
				height: 300,
				border: false,
				enableDD: false,
				viewConfig: {forceFit: true},
		        columns:[{
		            header: "文档",
		            width: 300,
		            dataIndex: 'project'
		        },{
		            header: "排序",
		            width: 30,
		            dataIndex: 'orderNumber'
		        },{
		            header: "表单模板",
		            width: 100,
		            dataIndex: 'template'
		        },{
		            header: "负责职务",
		            width: 100,
		            dataIndex: 'role'
		        }],
		        dataUrl: '/pdm/category/asyncCateModelTreeGrid.htm',
		        root: new Ext.tree.AsyncTreeNode({
		        	id: '0',
		            text: "模板节点"
		        }),
				tbar:[{
					id: "btn_model_new",
					text: "新建",
					tooltip: "新建阶段或文档",
					iconCls: 'cls_add_category_model',
					scope: this,
					handler: function(){
						var parent_id = document.getElementById("_selected_node_id").value;
						
						if(parent_id == ""){
							Ext.Msg.alert("Notice:","请先选择父目录！");
						} else {
							var cur_node = this.getSelectionModel().getSelectedNode();
							if(cur_node.isLeaf()){
								Ext.Msg.alert("提示：","不能选择在文件下创建文件夹！");
							}else{
								var json = cur_node.toJsonString(null,
									function(key, val) {
										return (key == 'project');
									}, {
										project: 'text'
									}
								);
				        		var obj = eval("("+json+")");
							
								var childNodeSize = cur_node.childNodes.length;
								
								var info = {};
								info.parentId = cur_node.id;
								info.nextOrder = childNodeSize+1;
								info.cateType = "D";
								info.parentName = obj.text;
							
								this.create_category_win = Ext.getCmp("createCategoryWin");
								
								if(typeof(this.create_category_win) != "object")
								{
									this.create_category_win = new CreateCategoryWin({_parentId: cur_node.id})
								}
								
								this.create_category_win.reset(info);
								this.create_category_win.show();
							}
						}
					}
				},'-',{
					id: 'btn_model_edit',
					text: "编辑",
					scope: this,
					iconCls: 'cls_edit_category',
					handler: function(){
						var cur_node = this.getSelectionModel().getSelectedNode();
						
						if(!cur_node){
							Ext.Msg.alert("提示：","请先选择父目录！");
						}else if(cur_node.id==46){
							Ext.Msg.alert("请注意","不能编辑模板根节点！");
						}else{
							jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
							try{
								var info = jsonrpc.jabsorbService.getEditCateInfo(cur_node.id);
							}catch(e){
								alert(e);
							}
							var jsonInfo = eval("("+info+")");
							if(!this.edit_category_win)
							{
								this.edit_category_win = new EditCategoryWin({node_info: jsonInfo});
							}
							this.edit_category_win.reset();
							this.edit_category_win.setValue(jsonInfo);
							
							this.edit_category_win.show();
						}
					}
				},'-',{
					id: 'btn_model_delete',
					text: "删除",
					iconCls: 'cls_remove_category_model',
					scope: this,
					handler: function(){
						
						var selectedItem = this.getSelectionModel().getSelectedNode();
						var bDoc = selectedItem.isLeaf();
						if(selectedItem.id == 46){
							Ext.Msg.alert("请注意：","不能删除根节点！");
						}else{
							var json = selectedItem.toJsonString(null,
								function(key, val) {
									return (key == 'project');
								}, {
									project: 'text'
								}
							);
			        		var obj = eval("("+json+")");
							
							Ext.MessageBox.show({
								title: "温馨提示：",
								msg: "您确认要删除["+obj.text+"] "+(bDoc?"模板":"阶段")+"？",
								buttons: Ext.MessageBox.YESNO,
								fn: function(btn){
									if(btn == 'yes')
									{
										var delMask = new Ext.LoadMask(Ext.getBody(), {
											msg: "信息删除中，请稍后...",
											removeMask: true
										});
										delMask.show();
										
										Ext.Ajax.request({
											url: '/pdm/category/deleteCateModel.htm',
											method: 'post',
											params: {
												cate_id: selectedItem.id
											},
											success: function(response,options){
												/*
												var result = Ext.decode(response.responseText).message;
												Ext.Msg.alert("信息:", result);
												*/
												delMask.hide();
												
												var tp_cate_model = Ext.getCmp("categoryModel_tree_grid");
									
												var parent_node = tp_cate_model.getSelectionModel().getSelectedNode().parentNode;
												parent_node.reload();
											},
											failure: function(response){
												var result = Ext.decode(response.responseText).message;
												Ext.Msg.alert("信息:", result);
											}
										});
									}
									else return;
								}
							});
						}
					}
				},'-',{
					id: 'btn_model_copy',
					text: "复制",
					scope: this,
					iconCls: 'cls_copy_template',
					tooltip: "复制模板",
					handler: function(){
						var cur_node = this.getSelectionModel().getSelectedNode();
						var childNodes = cur_node.childNodes;
						
						if(!cur_node)
						{
							Ext.Msg.alert("提示","请选择需要复制的目标模板.");
						}else if(childNodes.length>0){
							Ext.Msg.alert("提示","模板已存在，无需复制");
						}else{
							var json = cur_node.toJsonString(null,
								function(key, val) {
									return (key == 'project');
								}, {
									project: 'text'
								}
							);
			        		var obj = eval("("+json+")");
			        		
							if(!Ext.isEmpty(this.win_copyModel)) this.win_copyModel.destroy();
							
							this.win_copyModel = new CopyModelWin({id:"win_copyModel", targetName: obj.text, model_id: cur_node.id});
							this.win_copyModel.show();
						}
					}
				},'-',{
					id: "btn_doc_tmpl",
					text: "表单样式设定",
					scope: this,
					disabled: true,
					iconCls: 'cls_doc_tmpl',
					tooltip: "指定文档使用相应的表单页面",
					handler: function(){
						var cur_node = this.getSelectionModel().getSelectedNode();
						var cur_node_id = document.getElementById("_selected_node_id").value;
						if(!cur_node){
							Ext.Msg.alert("提示","请先选择相应的文档！");
						}
						else if(cur_node.isLeaf())
						{
							if(!this.setTemplateWin)
							{
								var templateGridPanel = new SetTemplateGrid({id:"setTemplateGrid", _cur_node_id: cur_node_id});
								this.setTemplateWin = new SetTemplateWin({id:"setTemplateWin", title: "设定使用表单页面模板", setTemplatePanel: templateGridPanel});
							}
							this.setTemplateWin.show();
							/*
							* 窗口弹出后再显示Loading图标
							*/
							this.setTemplateWin.setTemplatePanel.load();
						}else{
							Ext.Msg.alert("提示","只能对文档设定相应的表单样式！");
						}
						
					}
				},'-',{
					id: 'btn_assign_owner',
					text: "职务",
					scope: this,
					disabled: true,
					iconCls: 'cls_assign_owner',
					menu: {
						items: [{
							text: "添加",
							scope: this,
							iconCls: 'cls_assign_owner',
							tooltip: "指定相应文件或阶段的负责职位",
							handler: function(){
								var cur_node = this.getSelectionModel().getSelectedNode();
								if(!cur_node){
									Ext.Msg.alert("提示","请选择相应文档进行职务设定！");
								}else{
									var json = cur_node.toJsonString(null,
										function(key, val) {
											return (key == 'template'|| key == 'project');
										}, {
											template: 'sheet',
											project: 'document'
										}
									);
									var obj = eval("("+json+")");
								
									if(!this.setRoleWin)
									{
										var roleGridPnl = new SetRoleGrid({id:"setRoleGrid"});
										this.setRoleWin = new SetRoleWin({id:"setRoleWin", title: "对["+obj.document+"]设定默认职务", setRoleGrid: roleGridPnl});
									}
									this.setRoleWin.show();
									/*
									* 窗口弹出后再显示Loading图标
									*/
									this.setRoleWin.setRoleGrid.load();
								}
							}
						},{
							text: "清除",
							scope: this,
							handler: function(){
								var cur_node = this.getSelectionModel().getSelectedNode();
								if(Ext.isEmpty(cur_node))
								{
									Ext.Msg.alert("提示","请选择相应的文档!");
								}else{
									var delMask = new Ext.LoadMask(Ext.getBody(), {
										msg: "职务清除中，请稍后...",
										removeMask: true
									});
									delMask.show();
									
									Ext.Ajax.request({
										url: '/pdm/category/setCateRole.htm',
										method: 'post',
										params: {
											cateId: cur_node.id,
											action: "delete"
										},
										success: function(response,options){
											/*
											var result = Ext.decode(response.responseText).message;
											Ext.Msg.alert("信息:", result);
											*/
											delMask.hide();
											
											var parent_node = cur_node.parentNode;
											parent_node.reload();
										},
										failure: function(response){
											var result = Ext.decode(response.responseText).message;
											Ext.Msg.alert("信息:", result);
										}
									});
								}
							}
						}]
					}
				},"->",{
					id: 'btn_page_style_preview',
					text: "页面预览",
					scope: this,
					disabled: true,
					iconCls: "preview",
					handler: function(){
						var selectedItem = this.getSelectionModel().getSelectedNode();
						if(!selectedItem){
							Ext.Msg.alert("提示","请选择文档进行预览！");
						}else{
							var json = selectedItem.toJsonString(null,
								function(key, val) {
									return (key == 'template'|| key == 'tmplId');
								}, {
									template: 'name',
									tmplId: 'id'
								}
							);
							var obj = eval("("+json+")");
							if(obj.id!=0)
							{
								window.open("PreviewSheet.jsp?tmpl_id="+obj.id+"&tmplName="+obj.name, "", "height=460px, width=800px, toolbar=no, menubar=no, resizable=yes, scrollbars=yes");
							}else{
								Ext.Msg.alert("提示：","请选择表单进行预览页面");
							}
						}
					}
				},"-",{
					text: "刷新",
					scope: this,
					iconCls: "cls_table_refresh",
					handler: function(){
						this.root.reload(true,true);
					}
				}]
			});
			
			this.on('click',function(node){
				document.getElementById("_selected_node_id").value = node.id;
				if(node.isLeaf()){
					Ext.getCmp("btn_model_new").disable();
					Ext.getCmp("btn_doc_tmpl").enable();
					Ext.getCmp("btn_assign_owner").enable();
					Ext.getCmp("btn_page_style_preview").enable();
					Ext.getCmp("btn_model_delete").enable();
					Ext.getCmp("btn_model_edit").enable();
				}else{
					Ext.getCmp("btn_model_new").enable();
					Ext.getCmp("btn_doc_tmpl").disable();
					if(node.id == 46){
						Ext.getCmp("btn_assign_owner").disable();
						Ext.getCmp("btn_model_delete").disable();
						Ext.getCmp("btn_model_edit").disable();
					}else{
						Ext.getCmp("btn_assign_owner").enable();
						Ext.getCmp("btn_model_delete").enable();
						Ext.getCmp("btn_model_edit").enable();
					}
					Ext.getCmp("btn_page_style_preview").disable();
				}
		    });
		    
		    this.on('dblclick',function(node){
				var selectedItem = this.getSelectionModel().getSelectedNode();
				var json = selectedItem.toJsonString(null,
					function(key, val) {
						return (key == 'template'|| key == 'tmplId');
					}, {
						template: 'name',
						tmplId: 'id'
					}
				);
				var obj = eval("("+json+")");
				if(obj.id!=0)
				{
					window.open("PreviewSheet.jsp?tmpl_id="+obj.id+"&tmplName="+obj.name, "", "height=460px, width=800px, toolbar=no, menubar=no, resizable=yes, scrollbars=yes");
				}
		    });
		}
	});

/** =======================================================
 *  CreateCategoryWin.js
 ** ==================================================== */
	CreateCategoryWin = Ext.extend(Ext.Window,{
		categoryPanel: null,
		_parentId: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.categoryPanel = new CreateCategoryPanel({_parentId: this._parentId});
			
			CreateCategoryWin.superclass.constructor.call(this, {
				id: 'createCategoryWin',
				layout: 'fit',
				title: "新建窗口",
				width: 380,
				height: 270,
				resizable: false,
				modal: true,
				closeAction: 'hide',
				plain: true,
				buttonAlign: 'right',
				items: this.categoryPanel,
				buttons: [{
					text: "保存",
					disabled: false,
					handler: function(){
						
						var p = Ext.getCmp("createCategoryPanel");
						if( p.getForm().isValid() ) 
						{
							p.form.submit({
								url	 : '/pdm/category/createCategoryModel.htm',
								success : function(form,action)
								{
									/*
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									
									Ext.Msg.alert("温馨提示：",obj.message);
									*/
									var tp_cate_model = Ext.getCmp("categoryModel_tree_grid");
									var cur_node = tp_cate_model.getSelectionModel().getSelectedNode();
									cur_node.reload(true,true);
																		
									var w = Ext.getCmp("createCategoryWin");
									w.hide();
								},
								failure : function(form, action) 
								{
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									Ext.Msg.alert("温馨提示：",obj.message);
								},
								waitMsg : "信息保存中，请等待..."
							});
						}else{
							Ext.Msg.alert("提示", "信息提交失败!");
						}  
					}
				},{
					text: "关闭",
					scope: this,
					handler: function(){
						this.hide();
					}
				}]
			});
		},
		reset: function(info)
		{
			this.categoryPanel.form.reset();
			this.categoryPanel.form.setValues({
				"parent_id": info.parentId,
				"sort_order": info.nextOrder,
				"cate_type": info.cateType,
				"parentName": info.parentName
			});
		},
		setParentId: function(c){
			this.categoryPanel.form.setValues({
				"parent_id": c
			});
		}
	});

/** =======================================================
 *  CreateCategoryPanel.js
 ** ==================================================== */
	CreateCategoryPanel = Ext.extend(Ext.FormPanel,{
		_parentId: null,
		constructor: function(config){
		
			Ext.apply(this,config);
			
			CreateCategoryPanel.superclass.constructor.call(this, {
				labelWidth: 55,
				id: 'createCategoryPanel',
				frame: true,
				border: false,
				bodyStyle: 'padding:5px 5px 5px 5px',
				defaultType: 'textfield',
				items:[{
					fieldLabel: "名称",
					name: 'cate_name',
					allowBlank: false,
					maxLength: 100,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '90%',
					value: ''
				},{
					fieldLabel: "上级目录",
					name: 'parentName',
					allowBlank: false,
					readOnly: true,
					anchor: '90%',
					value: ''
				},{
					xtype: 'combo',
					fieldLabel: "类型",
					name: "cate_type",
					hiddenName: "cate_type",
					mode: 'local',
					allowBlank: false,
					blankText: '请选择类型',
					valueField: 'key',
					displayField: 'name',
					lazyRender: true,
					triggerAction: "all",
					typeAhead: true,
					anchor: '40%',
					value: 'D',
					store:new Ext.data.SimpleStore({
						fields: ['key', 'name'],
						data: [['D','文档'],['F','阶段'],['M','模板']]
					})
				},{
					xtype: 'numberfield',
					fieldLabel: '排列序号',
					name: 'sort_order',
					allowBlank: false,
					maxLength: 100,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '40%',
					value: '9999'
				},{
					xtype: 'textarea',
					fieldLabel: '备注',
					name: 'memo',
					allowBlank: true,
					maxLength: 150,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '89%',
					value: ''
				},{
					id: 'parent_id',
					name: 'parent_id',
					hidden: true,
					value: this._parentId
				}]
			});
		}
	});
/** =======================================================
 *  EditCategoryWin.js
 ** ==================================================== */
	EditCategoryWin = Ext.extend(Ext.Window,{
		editCategoryPanel: null,
		node_info: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.editCategoryPanel = new EditCategoryPanel({cur_node_info: this.node_info});
			
			EditCategoryWin.superclass.constructor.call(this, {
				id: 'editCategoryWin',
				layout: 'fit',
				title: "编辑窗口",
				width: 380,
				height: 250,
				resizable: false,
				modal: true,
				closeAction: 'hide',
				plain: true,
				buttonAlign: 'right',
				items: this.editCategoryPanel,
				buttons: [{
					text: "保存",
					disabled: false,
					handler: function(){
					
						var p = Ext.getCmp("editCategoryPanel");
						
						if( p.getForm().isValid() ) 
						{
							p.form.submit({
								url	 : '/pdm/category/editCategoryModel.htm',
								success : function(form,action)
								{
									/*
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									Ext.Msg.alert("温馨提示：", obj.message);
									*/
									var tp_cate_model = Ext.getCmp("categoryModel_tree_grid");
									var parent_node = tp_cate_model.getSelectionModel().getSelectedNode().parentNode;
									
									parent_node.reload(true,true);
									
									var w = Ext.getCmp("editCategoryWin");
									w.hide();
								},
								failure : function(form, action) 
								{
									var msg = action.response.responseText;
									var obj = Ext.decode( msg );
									Ext.Msg.alert("温馨提示：",obj.message);
								},
								waitMsg : '信息保存中，请等待...'
							});
						}else{
							Ext.Msg.alert('提示', '信息提交失败!');
						}  
					}
				},{
					text: '关闭',
					handler: function(){
						var w = Ext.getCmp("editCategoryWin");
						w.hide();
					}
				}]
			});
		},
		reset: function()
		{
			this.editCategoryPanel.form.reset();
		},
		setValue: function(value)
		{
			this.editCategoryPanel.form.setValues({
				"cate_name": value.cate_name,
				"cate_type": value.cate_type,
				"sort_order": value.sort_order,
				"memo": value.memo,
				"cate_id": value.cate_id
			});
		}
	});
/** =======================================================
 *  EditCategoryPanel.js
 ** ==================================================== */
	EditCategoryPanel = Ext.extend(Ext.FormPanel,{
		cur_node_info: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			EditCategoryPanel.superclass.constructor.call(this, {
				labelWidth: 55,
				id: 'editCategoryPanel',
				frame: true,
				border: false,
				bodyStyle: 'padding:5px 5px 5px 5px',
				defaultType: 'textfield',
				items:[{
					fieldLabel: "名称",
					name: 'cate_name',
					allowBlank: false,
					maxLength: 100,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '90%',
					value: this.cur_node_info ? this.cur_node_info.cate_name:""
				},{
					xtype: 'combo',
					fieldLabel: "类型",
					name: "cate_type",
					hiddenName: "cate_type",
					mode: 'local',
					blankText: '请选择类型',
					valueField: 'key',
					displayField: 'name',
					lazyRender: true,
					triggerAction: "all",
					typeAhead: true,
					anchor: '40%',
					value: this.cur_node_info ? this.cur_node_info.cate_type:"",
					store:new Ext.data.SimpleStore({
						fields: ['key', 'name'],
						data: [['F','阶段'],['D','文档'],['M','模板']]
					})
				},{
					xtype: 'numberfield',
					fieldLabel: '排列序号',
					name: 'sort_order',
					allowBlank: false,
					maxLength: 100,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '40%',
					value: this.cur_node_info ? this.cur_node_info.sort_order:""
				},{
					xtype: 'textarea',
					fieldLabel: '备注',
					name: 'memo',
					allowBlank: true,
					maxLength: 150,
					maxLengthText: "请缩减字数",
					msgTarget: 'side',
					anchor: '89%',
					value: this.cur_node_info ? this.cur_node_info.memo:""
				},{
					name: 'cate_id',
					hidden: true,
					value: this.cur_node_info ? this.cur_node_info.cate_id:""
				}]
			});
		}
	});
	
/****************************************************
 * @class SetTemplateWin
 * @extends Ext.ux.tree.TreeGrid
 ***************************************************/
	SetTemplateWin = Ext.extend(Ext.Window,{
		setTemplatePanel: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			SetTemplateWin.superclass.constructor.call(this, {
				layout: 'fit',
				width: 380,
				height: 480,
				resizable: false,
				modal: true,
				closeAction: 'hide',
				plain: true,
				buttonAlign: 'right',
				items: this.setTemplatePanel,
				buttons: [{
					text: "确定",
					disabled: false,
					scope: this,
					handler: function(){
						var r = this.setTemplatePanel.getSelectionModel().getSelected();
						
						if(typeof(r)=="undefined"){
							alert("请先选中表单模板！");
						}else{
							this.hide();
							
							Ext.Ajax.request({
								method: 'post',
								url: '/pdm/category/setCateTemplate.htm',
								params: {
									templateId: r.get("tmpl_id"),
									cateId: Ext.fly("_selected_node_id").dom.value
								},
								success: function(response,options){
									/*
									var result = Ext.decode(response.responseText).message;
									Ext.Msg.alert("信息:", result);
									*/
									var tg_cateModel = Ext.getCmp("categoryModel_tree_grid");
									var parentNode = tg_cateModel.getSelectionModel().getSelectedNode().parentNode;
									parentNode.reload(true,true);
								},
								failure: function(response){
									var result = Ext.decode(response.responseText).message;
									Ext.Msg.alert("信息:", result);
									return false;
								}
							});
						}
					}
				},{
					text: "关闭",
					scope: this,
					handler: function(){
						this.hide();
					}
				}]
			});
		}
	});
/****************************************************
 * @class SetTemplateGrid
 * @extends Ext.grid.GridPanel
 ***************************************************/
	SetTemplateGrid = Ext.extend(Ext.grid.GridPanel,{
		condition: null,
		store: null,
		cm: null,
		searchField: null,
		_cur_node_id: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.condition = {};
			this.condition.limit = 50;
			
			this.store = new Ext.data.Store({
			    baseParams: this.condition,   
				proxy: new Ext.data.HttpProxy({
					method: 'POST',
					url: '/pdm/category/getTemplateList.htm'
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalProperty',
					root: 'root',
					id: 'tmpl_id'
				},[
					{name: 'tmpl_id'},
					{name: 'tmplName'},
					{name: 'creator'},
					{name: 'dateOfCreate'},
					{name: 'memo'}
				])
			});
			this.cm = new Ext.grid.ColumnModel([
		        {
		           header: "模板名称",
		           dataIndex: 'tmplName',
		           sortable: true,
		           width: 180
		        },{
		           header: "备注",
		           dataIndex: 'memo',
		           sortable: true,
		           width: 70
		        }]);
	        
			this.searchField = new Ext.ux.form.SearchField({store: this.store, width:200});
			
			SetTemplateGrid.superclass.constructor.call(this, {
			    loadMask: {msg:'Loading...'},
			    viewConfig: {forceFit: true},
				region: 'center',
				border: false,
				height: 500,
				layout: 'fit',
				split: true,
				cls: 'x-rb',
				ds: this.store,
				sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
				cm: this.cm,
				trackMouseOver: false,
				tbar: ["查询：",this.searchField],
				bbar: new Ext.PagingToolbar({
					pageSize: 50,
					store: this.store,
					displayInfo: true
				})
			});
			
			this.on('rowdblclick',function(grid,rowIndex,e){
				var r = grid.getSelectionModel().getSelected();
				
				var setTemplateWin = Ext.getCmp("setTemplateWin");
				setTemplateWin.hide();
				
				Ext.Ajax.request({
					method: 'post',
					url: '/pdm/category/setCateTemplate.htm',
					params: {
						templateId: r.get("tmpl_id"),
						cateId: Ext.fly("_selected_node_id").dom.value
					},
					success: function(response,options){
						/*
						var result = Ext.decode(response.responseText).message;
						Ext.Msg.alert("信息:", result);
						*/
						var tg_cateModel = Ext.getCmp("categoryModel_tree_grid");
						var parentNode = tg_cateModel.getSelectionModel().getSelectedNode().parentNode;
						parentNode.reload(true,true);
					},
					failure: function(response){
						var result = Ext.decode(response.responseText).message;
						Ext.Msg.alert("信息:", result);
						return false;
					}
				});
			});
		},
		load: function(){
			this.store.load();
		}
	});
	
/****************************************************
 * @class SetRoleWin
 * @extends Ext.Window
 ***************************************************/
	SetRoleWin = Ext.extend(Ext.Window,{
		setRoleGrid: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			SetRoleWin.superclass.constructor.call(this, {
				layout: 'fit',
				width: 380,
				height: 480,
				resizable: false,
				modal: true,
				closeAction: 'hide',
				plain: true,
				buttonAlign: 'right',
				items: this.setRoleGrid,
				buttons: [{
					text: "确定",
					disabled: false,
					scope: this,
					handler: function(){
						var r = this.setRoleGrid.getSelectionModel().getSelected();
						
						if(typeof(r)=="undefined"){
							Ext.Msg.alert("提示","请先选中需要的职务！");
						}else{
							this.hide();
							Ext.Ajax.request({
								method: 'post',
								url: '/pdm/category/setCateRole.htm',
								params: {
									roleId: r.get("role_id"),
									cateId: Ext.fly("_selected_node_id").dom.value,
									action: "add"
								},
								success: function(response,options){
									/*
									var result = Ext.decode(response.responseText).message;
									Ext.Msg.alert("信息:", result);
									*/
									var tg_cateModel = Ext.getCmp("categoryModel_tree_grid");
									var parentNode = tg_cateModel.getSelectionModel().getSelectedNode().parentNode;
									parentNode.reload(true,true);
								},
								failure: function(response){
									var result = Ext.decode(response.responseText).message;
									Ext.Msg.alert("信息:", result);
									return false;
								}
							});
						}
					}
				},{
					text: "关闭",
					scope: this,
					handler: function(){
						this.hide();
					}
				}]
			});
		}
	});
/****************************************************
 * @class SetRoleGrid
 * @extends Ext.grid.GridPanel
 ***************************************************/
	SetRoleGrid = Ext.extend(Ext.grid.GridPanel,{
		condition: null,
		store: null,
		cm: null,
		searchField: null,
		_cur_node_id: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.condition = {};
			this.condition.limit = 50;
			
			this.store = new Ext.data.Store({
			    baseParams: this.condition,   
				proxy: new Ext.data.HttpProxy({
					method: 'POST',
					url: '/pdm/role/getAllRoleList.htm'
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalProperty',
					root: 'root',
					id: 'role_id'
				},[
					{name: 'role_id'},
					{name: 'roleName'},
					{name: 'memo'}
				])
			});
			this.cm = new Ext.grid.ColumnModel([
		        {
		           header: "职务名称",
		           dataIndex: 'roleName',
		           sortable: true,
		           width: 180
		        },{
		           header: "备注",
		           dataIndex: 'memo',
		           sortable: true,
		           width: 70
		        }]);
	        
	        //this.store.load();
			//this.searchField = new Ext.ux.form.SearchField({store: this.store, width:200});
			
			SetRoleGrid.superclass.constructor.call(this, {
			    loadMask: {msg:'Loading...'},
			    viewConfig: {forceFit: true},
				region: 'center',
				border: false,
				height: 500,
				layout: 'fit',
				split: true,
				cls: 'x-rb',
				ds: this.store,
				columnLines: true,
				stripeRows: true,
				sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
				cm: this.cm,
				trackMouseOver: false,
				//tbar: ["查询：",this.searchField],
				bbar: new Ext.PagingToolbar({
					pageSize: 50,
					store: this.store,
					displayInfo: true
				})
			});
			this.on('rowdblclick',function(grid,rowIndex,e){
				var r = grid.getSelectionModel().getSelected();
				
				var setRoleWin = Ext.getCmp("setRoleWin");
				setRoleWin.hide();
				
				Ext.Ajax.request({
					method: 'post',
					url: '/pdm/category/setCateRole.htm',
					params: {
						roleId: r.get("role_id"),
						cateId: Ext.fly("_selected_node_id").dom.value,
						action: "add"
					},
					success: function(response,options){
						/*
						var result = Ext.decode(response.responseText).message;
						Ext.Msg.alert("信息:", result);
						*/
						var tg_cateModel = Ext.getCmp("categoryModel_tree_grid");
						var parentNode = tg_cateModel.getSelectionModel().getSelectedNode().parentNode;
						parentNode.reload(true,true);
					},
					failure: function(response){
						var result = Ext.decode(response.responseText).message;
						Ext.Msg.alert("信息:", result);
						return false;
					}
				});
			});
		},
		load: function(){
			this.store.load();
		}
	});
	
/****************************************************
 * @class CopyModelWin
 * @extends Ext.Window
 ***************************************************/
	CopyModelWin = Ext.extend( Ext.Window, {
		pnl_id: null,
		model_id: null,
		targetName: null,
		constructor: function(config){
			Ext.apply(this, config);
			
			if(this.pnl_id==null) this.pnl_id = Ext.id();
			
			CopyModelWin.superclass.constructor.call(this, {
				layout: 'fit',
				width: 380,
				height: 220,
				modal: true,
				plain: true,
				border: true,
				resizable: false,
				autoDestroy: true,
				closeAction: 'hide',
				buttonAlign: 'right',
				items: [{
					xtype: 'panel',
					labelWidth: 55,
					frame: false,
					border: false,
					layout: 'form',
					bodyStyle: 'padding: 5px 5px 5px 5px',
					items: [{
						id: this.pnl_id,
						xtype: 'panel',
						frame: false,
						border: false,
						anchor: '90%',
						html: "请在下面选择框中选择需要复制的模板，选择完毕后点击保存，系统将会将模板复制到您已选择的目标节点[<b><font color=red>"+this.targetName+"</font></b>]下<br/><br/><br/>"
					},{
						xtype: 'combo',
						fieldLabel: "模板名称",
						name: 'cb_copy_model',
						forceSelection: true,
						store: new Ext.data.JsonStore({
							url: '/pdm/category/getCopyModel.htm'+'?model_id='+this.model_id,
							totalProperty: 'totalProperty',
							root: 'root',
							fields: ['key','name']
						}),
						valueField: 'key',
						displayField: 'name',
						emptyText: "请选择模板...",
						loadingText: "正在加载所有模板",
						typeAhead: true,
						mode: 'remote',
						anchor: '90%',
						editable: false,
						triggerAction: 'all',
						selectOnFocus: true,
						listeners: {
						    select: function(combo, record, index) {
								var model_id = record.data.key;
								Ext.fly("cp_model_id").dom.value = model_id;
							}
						}
					},{
						xtype: 'hidden',
						value: '-1',
						hidden: true,
						name: 'cp_model_id'
					}]
				}],
				buttons: [{
					text: "复制",
					scope: this,
					handler: function(){
						var cateModel_tree = Ext.getCmp("categoryModel_tree_grid");
						var cur_node = cateModel_tree.getSelectionModel().getSelectedNode();
						
						if(Ext.fly("cb_copy_model").dom.value == "请选择模板..."||Ext.fly("cb_copy_model").dom.value == "")
						{
							Ext.Msg.alert("提示","请选择需要复制的模板");
						}else{
							var copyMask = new Ext.LoadMask(Ext.getBody(), {
								msg: "模板复制中，请稍后...",
								removeMask: true
							});
							copyMask.show();
							
							Ext.Ajax.request({
								url: '/pdm/category/copyModel.htm',
								method: 'post',
								params: {
									target_id: cur_node.id,
									model_id: Ext.fly("cp_model_id").dom.value
								},
								success: function(response, options){
									var win = Ext.getCmp("win_copyModel");
									win.hide();
									
									cateModel_tree.loader.load(cur_node);
									
									copyMask.hide();
								},
								failure: function(response, options){
									var result = Ext.decode(response.responseText).message;
									Ext.Msg.alert("信息:", result);
								}
							});
						}
						
						
						
					}
				},{
					text: "关闭",
					scope: this,
					handler: function(){
						this.hide();
					}
				}]
			});
		},
		setTargetName: function(c){
			this.targetName = c;
		}
	});	